import axios from 'axios'
import Vue from 'vue';
import { Notify } from 'vant';
import router from '../../router/index.js'

Vue.use(Notify);

export default {
	state: {
		token: ''
	},
	mutations: {
	login(state, value){
		state.token = value
	}
	},
	actions: {
		async login({
			commit
		}, value) {
			let data = await axios.post('http://localhost:9090/login', value)
			
			if(data.code == '401'){
				Notify({ type: 'warning', message: '账号或密码错误' });
			}else{
				Notify({ type: 'success', message: '登录成功' });
				router.push({path:'/center'})
			}
			
			console.log(data)
			sessionStorage.setItem('token',data.data.token)
			sessionStorage.setItem('username',data.data.username)
			commit('login',data.data.token)
		}
},

}
